package edu.scdx.dao;
import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import edu.scdx.entity.Cart;

@Repository
public interface CartMapper {

	@Select("select * from cart where tel=#{tel} and id=#{id}")
	Cart getCart(@Param("tel")String userTel,@Param("id")int id);

	@Select("insert into cart(tel,id,number,name,type,author,publisher,description,price,kou) values(#{tel},#{id},#{number},#{name},#{type},#{author},#{publisher},#{description},#{price},#{kou})")
	void addCart(@Param("tel")String userTel,@Param("id") int id, @Param("number") int number,@Param("name") String name, @Param("type")String type, @Param("author")String author,@Param("publisher") String publisher,@Param("description") String description,@Param("price") double price, @Param("kou")double kou);

	@Select("update cart set number=number+1 where tel=#{tel} and id=#{id}")
	void updateCart(@Param("tel")String userTel,@Param("id") int id);

	List<Cart> getAll(String userTel);

	@Select("delete from cart where tel=#{tel} and id=#{id} ")
	void deleteCart(@Param("tel")String tel,@Param("id") Integer id);

	
	@Select("select * from cart where tel=#{tel} and id=#{id}")
	Cart getCartNumber(@Param("tel")String tel, @Param("id")Integer id);

	@Select("update cart set number=number-1 where tel=#{tel} and id=#{id}")
	void updateCartNumber(@Param("tel")String tel,@Param("id")Integer id);

}
